package com.itheima.mapper;

//持久层窗口

import com.itheima.domain.Student;
import org.apache.ibatis.annotations.*;

import java.util.ArrayList;
import java.util.List;

public interface StudentMapper {

    @Insert("insert into student values(null,#{name},#{age})")
    public Integer add(Student stu);

    @Delete("delete from student where id=#{id}")
    public Integer delete(Integer id);

    @Update("UPDATE student SET name=#{name},age=#{age} WHERE id=#{id}")
    public Integer update(Student stu);

    @Select("select * from student")
    public ArrayList<Student> findAll();

    /*添数据并返回最后添加的id*/
    @Insert("insert into student values(null,#{name},#{age})")
    @SelectKey(keyColumn = "id",keyProperty = "id",resultType = int.class,before =false,statement = "select last_insert_id()")
    public Integer addReturnId(Student stu);

    /*根据id查询*/
    @Select("select * from student where id=#{id}")
    public Student selectById(Integer id);

    /*模糊查询*/
    @Select("SELECT * FROM student WHERE NAME LIKE CONCAT('%',#{name},'%')")
    public List<Student> selectByName(String name);

    /*统计查询*/
    @Select("SELECT COUNT(*) FROM student")
    public Integer findCount();

    /*多条件查询*/
    @Select("select * from student where name=#{name} or age=#{age}")
    public List<Student> findByNameOrAge(@Param("name") String n,@Param("age")Integer a);








}
